<%--
  Created by IntelliJ IDEA.
  User: 36061
  Date: 2024/9/25
  Time: 9:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@page import="java.sql.*" %>
<% request.setCharacterEncoding("UTF-8");%>
<% String id = request.getParameter("stuid");%>
<% String stuName = request.getParameter("stuname");%>
<% String stuBirthday = request.getParameter("date");%>
<% String stuClass = request.getParameter("stuclass");%>
<html>
<head>
    <title>条件查询</title>
    <%
        String dbName = "school";//数据库
        String userName ="root";//账户
        String userPassword ="qwert";//密码
        String url ="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPassword;
        Class.forName("com.mysql.cj.jdbc.Driver");//5.7以下不加.cj
        Connection conn = DriverManager.getConnection(url);//连接数据库
        Statement statement = conn.createStatement();//创建操作对象
        String sql = "insert into student value('"+id+"','"+stuName+"','"+stuBirthday+"','"+stuClass+"')";//查询学生表所有字段
        int rsult = statement.executeUpdate(sql);//运行sql命令查询数据 结果放到rs结果集中
        if (rsult>0){
            out.print("<script>alert('添加成功')</script>");
        }else {
            out.print("<script>alert('添加失败')</script>");
        }
        sql = "select  * from student";
        ResultSet rs = null;
        rs = statement.executeQuery(sql);
    %>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
<table class="layui-table" lay-even>
    <caption>学生标信息</caption>
    <thead>
    <tr>
        <th>学号</th>
        <th>姓名</th>
        <th>出生日期</th>
        <th>所在班级</th>
    </tr>
    </thead>
    <tbody>
    <% while (rs.next()){%>
    <tr>
        <td><%=rs.getString(1) %></td>
        <td><%=rs.getString(2) %></td>
        <td><%=rs.getString(3) %></td>
        <td><%=rs.getString(4) %></td>
    </tr>
    <% } %>
    <%
        rs.close();
        statement.close();
        conn.close();
    %>
    </tbody>
</table>
</body>
</html>